<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="edu.fau.scanny.r.*"%>
<%@ page import="edu.fau.scanny.r.stromal.servlet.*"%>
<%@ page import="org.apache.commons.lang.StringUtils"%>
<%@ page import="edu.fau.scanny.stromal.*"%>
<%@ page import="edu.fau.scanny.r.stromal.model.*"%>
<%@ page import="java.text.DecimalFormat"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Stromal Signal Calculator</title>
<script type="text/javascript">
	function selectRadio(n) {

		document.forms.stromal[n][3].checked = true

	}
</script>
<link rel="stylesheet" href="css/table.css">
</head>
<body>
	<table class="center">
		<tr>
			<td><a href="process.jsp"
				title="Click to see process description."><img
					src="img/page2_banner_2.png" height="400" width="1000" /></a></td>
		</tr>
	</table>
	<h1 style="text-align: center">Stromal Signal Calculator</h1>
	<table class="center">
		<tr>
			<td colspan=4>
				<h2>1. Verify Normalization:</h2>
			</td>
		</tr>
		<%
			String boxplot = request.getAttribute("boxplot").toString();
			boxplot = boxplot.replace("\\", "/");
		%>
		<tr>
			<td class="centerCenter"><img
				src="<%=request.getAttribute("boxplot")%>" height="400" width="400" /></td>
		</tr>
		<tr>
			<td class="centerCenter">
				<form method="post" action="download" name="downloadNorm">
					<input type="hidden" name="file"
						value="<%=request.getAttribute("normFile")%>" />
					<button value="submit" name="submit">
						<big>Normalized Signal Values Text File</big>
					</button>
				</form>
			</td>
		</tr>
	</table>



	<form method="post" action="stromal" name="stromal" target="_blank">
		&nbsp;&nbsp;&nbsp;<br> <input type="hidden" name="workspaceFile"
			value="<%=request.getAttribute("workspaceFile")%>" /> <input
			type="hidden" name="log2" value="<%=request.getAttribute("log2")%>" />
		<input type="hidden" name="wholePartVar"
			value="<%=request.getAttribute("wholePartVar")%>" /> <input
			type="hidden" name="normalization"
			value="<%=request.getAttribute("normalization")%>" />
		<table class="center">
			<tr>
				<td colspan=4>
					<h2>
						2. Select Your P<small>Lymphoid</small> Values:
					</h2>

				</td>
			</tr>
			<tr>
				<td colspan=4>You must provide an estimate of the proportion of
					signal in whole tissue that is contributed by lymphocytes (P<sub>Lymphoid</sub>).
					Theoretically, the y-intercept of a rank-ordered graph of the
					tissue:lymphoid signal ratio for each probeset on the chip should
					accurately describe the true P<sub>Lymphoid</sub> (<a
					href="http://bioinformatics.oxfordjournals.org/content/23/24/3328.long">1</a>).In
					reality, noise and other factors distort the signal ratios such
					that a y-intercept is not estimated in any reasonable fashion (<a
					href="http://bioinformatics.oxfordjournals.org/content/23/24/3328.long">1</a>,
					<a href="http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2807413/">2</a>).
					As a consequence, three different methods of estimating P<sub>Lymphoid</sub>
					are provided, as described below.
				</td>
			</tr>
			<tr>
				<td colspan=4>
					<ol>
						<li>Lymphoid-specific gene estimate (<a
							href="http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2807413/">2</a>):
							average tissue:lymphoid signal ratios of a manually curated list
							of genes known to be expressed by lymphoid cells but not by other
							cell types (Rag1, CD4, Lck, etc);
						</li>
						<li>Perpendicular: the y-intercept of a line perpendicular to
							the inflection point of a rank-ordered graph of tissue:lymphoid
							signal ratios for each probeset on the chip (<a
							href="http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2807413/">2</a>);
						</li>
						<li>Tangent: the y-intercept of a line tangent to the
							inflection point of a rank-ordered graph of tissue:lymphoid
							signal ratios for each probeset on the chip (<a
							href="http://www.ncbi.nlm.nih.gov/pmc/articles/PMC2807413/">2</a>).
						</li>
					</ol>
				</td>
			</tr>
			<tr>
				<td colspan=4>You may choose the value generated by one of these
					approaches, or enter a value inside or outside the range, depending
					on your objectives: a higher P<sub>Lymphoid</sub> results in more
					false negatives and fewer false positives, while a lower P<sub>Lymphoid</sub>
					results in the opposite. You will be able to estimate the validity
					of your choice of P<sub>Lymphoid</sub> value by comparing the
					distirbutions of stromal-specific vs lymphoid-specific genes and
					Affy Mask genes on the Results page.
				</td>
			</tr>
			<tr>
				<td colspan=4>Your estimates of P<sub>Lymphoid</sub> for
					selected samples are shown below.
				</td>
			</tr>

			<%
				Map<String, GroupOutput> groupOutputs = (Map<String, GroupOutput>) request.getAttribute("groupOutputs");
				for (String group : groupOutputs.keySet()) {
					GroupOutput go = groupOutputs.get(group);
					String groupS = StringUtils.replace(group, " ", "");
					DecimalFormat df = new DecimalFormat("###.####");
			%>
			<tr>
				<td style="text-align: left;" colspan=4><h3><%=group%>:
					</h3></td>
			</tr>
			<tr>

				<td>
					<table>
						<tr>
							<td style="text-align: left;"><input name="<%=groupS%>"
								value="<%=df.format(go.getpSpecific())%>" type="radio" checked></td>
							<td style="color:green;">Lymphoid-Specific:</td>
							<td><%=df.format(go.getpSpecific())%></td>

						</tr>

						<tr>
							<td style="text-align: left;"><input name="<%=groupS%>"
								value="<%=df.format(go.getpTangent())%>" type="radio"></td>
							<td style="color:blue;">Tangent:</td>
							<td><%=df.format(go.getpTangent())%></td>
						</tr>
						<tr>
							<td style="text-align: left;"><input name="<%=groupS%>"
								value="<%=df.format(go.getpPer())%>" type="radio"></td>
							<td style="color:red;">Perpendicular:</td>
							<td><%=df.format(go.getpPer())%></td>
						</tr>
						<tr>
							<td style="text-align: left;"><input name="<%=groupS%>"
								value="plymphUser" type="radio"></td>
							<td>Other Estimate:</td>
							<td><input type="text" name="<%=groupS + "_plymphoid"%>"
								onclick="selectRadio('<%=groupS%>')" /></td>
						</tr>
					</table>
				</td>
				<td><img src="<%=go.getRorPlot().getName()%>" height="400"
					width="400" /></td>
			</tr>

			<tr>
				<td><input type="hidden" name="<%=go.getPresentCallVarIndv()%>"
					value="<%=go.getPresentCallVarIndv()%>" /> &nbsp;&nbsp;&nbsp; <br></td>
			</tr>

			<%
				}
			%>
		</table>
		<table class="centerCenter">
			<tbody>
				<tr>
					<td style="height: 66px; text-align: center;" colspan="2"
						rowspan="1">
						<button value="submit" name="submit">
							<strong>Submit</strong>
						</button>

					</td>
				</tr>
			</tbody>
		</table>
		<table class="center">
			<tr>
				<td colspan=2>Parameters:</td>
			</tr>
			<tr>
				<td><%=request.getAttribute("normalization")%> normalization<br />
					<%=WebPageStringUtils.log2S(request.getAttribute("log2"))%> output
					signal</td>
			</tr>
		</table>
		<table class="border">
			<tr>
				<td class="border">Time Point</td>
				<%
					Map<String, Map<String, List<CelFile>>> groupFilesMap = (HashMap<String, Map<String, List<CelFile>>>) request
							.getAttribute("groupMap");
					Map<Integer, String> orderMap = MetaFileUtils.orderMap(this.getServletContext().getRealPath("Order.txt"));

					for (int kk = 1; kk <= orderMap.size(); kk++) {
						String order = orderMap.get(kk);
				%>
				<td class="border" style="text-align: center;"><%=order%></td>
				<%
					}
				%>
			</tr>
			<%
				for (String group : groupFilesMap.keySet()) {
					Map<String, List<CelFile>> typeMap = groupFilesMap.get(group);
			%>
			<tr>
				<td class="border"><%=group%></td>

				<%
					for (int kk = 1; kk <= orderMap.size(); kk++) {
							String order = orderMap.get(kk);
							List<CelFile> celFiles = typeMap.get(order);
				%>
				<td class="border" style="text-align: center;">
					<table style="text-align: center;">
						<%
							for (CelFile celFile : celFiles) {
						%>
						<tr style="text-align: center;">
							<td style="text-align: center;"><a
								style="text-align: center;"
								title="Percent Present = <%=celFile.getpPresent() + "\n"%>Scaling Factor = <%=celFile.getScalingFactor()%>"><%=celFile.getShortName()%></a><input
								type="hidden" name="celFiles" value="<%=celFile.getChipFile()%>" /></td>
						</tr>

						<%
							}
						%>
					</table>
				</td>
				<%
					}
				%>
			</tr>
			<%
				}
			%>
		</table>
		<table class="center">
			<tr>
				<td><b>*Mouse over sample name to view QC values.</b></td>
			</tr>
		</table>
	</form>

	<table class="center">
		<tr>
			<td><a href="Reference.html">References Page</a></td>
		</tr>
	</table>
</body>
</html>